<?php

include_once "model/bean/Account.php";
include_once "model/dao/AccountDao.php";
include_once "model/service/BaseManager.php";

class AccountManager extends BaseManager {

	public function __construct() {
		$this->dao = new AccountDao(Config::getDateSourceName(), Config::$db_user, Config::$db_password);
	}

	
	public function selectCategory($type) {
		return $this->dao ? $this->dao->selectCategory($type) : null;
	}
	
	public function statisticByDay() {
		$query = <<<SQL
		SELECT
			account_date AS date,
			account_type AS type,
			count(*) AS count,
			sum(account_amount) AS amount
		FROM money_account
		GROUP BY date, type
		ORDER BY date desc;
SQL;
		$result = $this->dao ? $this->dao->execute($query) : null;

		return $result;
	}
}
?>